package org.example.controller;

import org.example.config.gaud.AmapGeocoder;
import org.example.domain.CabinetMachine;
import org.example.domain.ExpressPackage;
import org.example.domain.ExpressVo;
import org.example.model.common.Result;
import org.example.model.common.ResultCodeEnum;
import org.example.service.IExpressPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 包裹Controller
 *
 * @author ruoyi
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/package")
public class ExpressPackageController{
    @Autowired
    private IExpressPackageService expressPackageService;

    /**
     * 查询包裹列表
     */
    @GetMapping("/list/{deliveryid}")
    public ExpressVo list(@PathVariable Long deliveryid) {
        return expressPackageService.selectExpressPackageList(deliveryid);
    }

    /**
     * 获取包裹详细信息
     */
    @GetMapping(value = "/{id}")
    public ExpressPackage getInfo(@PathVariable("id") Long id) {
        return expressPackageService.selectExpressPackageById(id);
    }

    @GetMapping("getaddress/{id}")
    public Result getaddress(@PathVariable Integer id) {
        List<CabinetMachine> cabinetMachine1 = expressPackageService.findCabinetMachine(id);
        System.out.println(cabinetMachine1);
        String address = null;
        if(cabinetMachine1!=null&&!cabinetMachine1.isEmpty()){
            address = cabinetMachine1.get(0).getLocation();
            System.out.println(address);
        }
        Map<String, String> geocoderLatitude = AmapGeocoder.getGeocoder(address);
        return Result.build(geocoderLatitude, ResultCodeEnum.SUCCESS);
    }
}
